package com.junzhiit.nengji.shop.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.NoSuchMessageException;
import org.springframework.stereotype.Service;

import com.bainaeco.framework.enums.Lang;
import com.junzhiit.nengji.shop.service.MessageService;

@Service
public class MessageServiceImpl extends BaseServiceImpl implements MessageService {

	@Autowired
	private ApplicationContext applicationContext;

	public String getMessage(int errorCode, Object[] args, String lang) {
		String errorMessage = "";
		try {
			errorMessage = applicationContext.getMessage(String.valueOf(errorCode), args, Lang.toLang(lang).toLocale());
		} catch (NoSuchMessageException ex) {
			logger.warn(ex.getMessage());
		}
		return errorMessage;
	}

	public String getMessage(String key, Object[] args, String lang) {
		String errorMessage = "";
		try {
			errorMessage = applicationContext.getMessage(key, args, Lang.toLang(lang).toLocale());
		} catch (NoSuchMessageException ex) {
			logger.warn(ex.getMessage());
		}
		return errorMessage;
	}
}
